﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace VASJ.Service
{
    [ServiceContract]
    public interface IAcpInetService
    {
        [OperationContract]
        AcpInetResult Login(string username, string password);

        [OperationContract]
        AcpInetResult CreateUser(string username, string password);

        [OperationContract]
        AcpInetResult CreateNewUser(string username, string password, string email);

        [OperationContract]
        AcpInetResult ChangePassword(string username, string oldpassword, string newpassword);

        [OperationContract]
        AcpInetResult Logout(Guid Token);

        [OperationContract]
        AcpInetResult GetPermissions(Guid Token, int ProductId, int ProjectId, string PermissionId);
    }

    [DataContract]
    public class AcpInetResult
    {
        [DataMember]
        public int Code { get; set; }

        [DataMember]
        public string Message { get; set; }

        [DataMember]
        public Guid Token { get; set; }

        [DataMember]
        public DateTime TokenExpired { get; set; }

        [DataMember]
        public List<string> PermissionData { get; set; }

        [DataMember]
        public List<ProductData> ProductData { get; set; }

        [DataMember]
        public List<ProjectData> ProjectData { get; set; }

        /// <summary>
        /// Init
        /// </summary>
        public AcpInetResult()
        {
            this.PermissionData = new List<string>();
            this.ProductData = new List<ProductData>();
            this.ProjectData = new List<ProjectData>();
        }
    }

    [DataContract]
    public class ProductData
    {
        [DataMember]
        public int ProductID { get; set; }

        [DataMember]
        public string ProductName { get; set; }

        /// <summary>
        /// Init
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="productName"></param>
        public ProductData(int productId, string productName)
        {
            this.ProductID = productId;
            this.ProductName = productName;
        }

        /// <summary>
        /// Compare
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public int CompareTo(ProductData b)
        {
            // Alphabetic sort name[A to Z]
            return this.ProductName.CompareTo(b.ProductName);
        }
    }

    [DataContract]
    public class ProjectData
    {
        [DataMember]
        public int ProjectID { get; set; }

        [DataMember]
        public string ProjectName { get; set; }

        /// <summary>
        /// 0: Owner; 1: Joined
        /// </summary>
        [DataMember]
        public int Type { get; set; }

        /// <summary>
        /// Init
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="projectName"></param>
        /// <param name="type"></param>
        public ProjectData(int projectId, string projectName, int type)
        {
            this.ProjectID = projectId;
            this.ProjectName = projectName;
            this.Type = type;
        }

        /// <summary>
        /// Compare
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public int CompareTo(ProjectData b)
        {
            // Alphabetic sort name[A to Z]
            return this.ProjectName.CompareTo(b.ProjectName);
        }
    }
}
